<?php

/**
 * Description of a
 * 
 * @author 叶风
 * Qq:    355007778
 * Email: ye.fn@163.com
 */

namespace c\shop\order;
\control::$template_dir = TEMPLATE_DIR_A;
\YF_f::initC('\c\auth\permission')->check('shop\order');

class a extends b
{

    function index_home()
    {
        $this->_home();
    }
    function index_view()
    {
        $ord = $this->db->getOne($this->table, '*', 'id='. intval($_GET['id']));
        $this->isExist($ord); 
        
        \control::$template_dir = TEMPLATE_DIR_F;
        $this->_view($ord);       
    }
    function index_del()
    {
        $w = ' AND state IN(0)';
        $this->_del($w);
    }
    //发货
    function index_sendGoods()
    {
		$p = $_POST;
        $da = array('expre_name'=>$p['expre_name'],'expre_id'=>$p['expre_id'], 'expre_code'=>$p['expre_code'], 'state'=>3);
        $id = intval($_GET['id']);
        $b = $this->db->save($this->table, $da, 'id='.$id . ' AND state=2');
        if ($b)
         {
            $this->flow($id, \lang::g('Send goods.'), 'Seller');
            \log::write('shop_order', 'sendGoods', $id);
            ajax_json(TRUE);
         }
        else
            ajax_json(\lang::g('save fail'));
    }
    
    //edit
    function index_edit()
    {
        $id = intval($_GET['id']); 
        if ($_POST)
         {
            $d = $_POST['d'];

            $data = array();
            $_data = array('expre_fee','expre_code','pay_money','state');
            foreach ($_data as $k)
                isset($d[$k]) && $data[$k] = $d[$k];
            
            $b = $this->db->save($this->table, $data, 'id='.$id);
            if ($b)
             {
                $this->flow($id, \lang::g('Edit order.'), 'Seller');
                \log::write('shop_order', 'edit', $id);
                ajax_json(TRUE);
             }
            else
                ajax_json(\lang::g('save fail'));
         }
        
        $da = $this->db->getOne($this->table, '*', 'id='.$id);
        $this->loadTemplate('shop/order/edit', array('data'=>$da));
        $this->display('');
    }
}
